using Microsoft.AspNetCore.Components;

namespace Microsoft.FluentUI.AspNetCore.Components;

public partial class FluentSplashScreen : IDialogContentComponent<SplashScreenContent>

{
    public const string LOGO = """
        <svg class="icon" focusable="false" viewBox="0 0 60 20" aria-hidden="true" >
            <svg viewBox="0 0 338 72" fill="none" xmlns="http://www.w3.org/2000/svg">
                <g clip-path="url(#clip0)">
                    <path d="M140.4 14.4V57.6H132.9V23.7H132.8L119.4 57.6H114.4L100.7 23.7H100.6V57.6H93.7V14.4H104.5L116.9 46.4H117.1L130.2 14.4H140.4V14.4ZM146.6 17.7C146.6 16.5 147 15.5 147.9 14.7C148.8 13.9 149.8 13.5 151 13.5C152.3 13.5 153.4 13.9 154.2 14.8C155 15.6 155.5 16.6 155.5 17.8C155.5 19 155.1 20 154.2 20.8C153.3 21.6 152.3 22 151 22C149.7 22 148.7 21.6 147.9 20.8C147.1 19.8 146.6 18.8 146.6 17.7ZM154.7 26.6V57.6H147.4V26.6H154.7ZM176.8 52.3C177.9 52.3 179.1 52 180.4 51.5C181.7 51 182.9 50.3 184 49.5V56.3C182.8 57 181.5 57.5 180 57.8C178.5 58.1 176.9 58.3 175.1 58.3C170.5 58.3 166.8 56.9 164 54C161.1 51.1 159.7 47.4 159.7 43C159.7 38 161.2 33.9 164.1 30.7C167 27.5 171.1 25.9 176.5 25.9C177.9 25.9 179.2 26.1 180.6 26.4C182 26.8 183.1 27.2 183.9 27.6V34.6C182.8 33.8 181.6 33.1 180.5 32.7C179.3 32.2 178.1 32 176.9 32C174 32 171.7 32.9 169.9 34.8C168.1 36.7 167.2 39.2 167.2 42.4C167.2 45.5 168 48 169.7 49.7C171.6 51.4 173.9 52.3 176.8 52.3ZM204.7 26.1C205.3 26.1 205.8 26.1 206.3 26.2C206.8 26.3 207.2 26.4 207.5 26.5V33.9C207.1 33.6 206.6 33.4 205.8 33.1C205.1 32.8 204.2 32.7 203.1 32.7C201.3 32.7 199.8 33.5 198.6 35C197.4 36.5 196.7 38.8 196.7 42V57.6H189.4V26.6H196.7V31.5H196.8C197.5 29.8 198.5 28.5 199.8 27.5C201.2 26.6 202.8 26.1 204.7 26.1ZM207.9 42.6C207.9 37.5 209.3 33.4 212.2 30.4C215.1 27.4 219.1 25.9 224.3 25.9C229.1 25.9 232.9 27.3 235.6 30.2C238.3 33.1 239.7 37 239.7 41.9C239.7 46.9 238.3 50.9 235.4 53.9C232.5 56.9 228.6 58.4 223.6 58.4C218.8 58.4 215 57 212.2 54.2C209.3 51.3 207.9 47.4 207.9 42.6ZM215.5 42.3C215.5 45.5 216.2 48 217.7 49.7C219.2 51.4 221.3 52.3 224 52.3C226.7 52.3 228.7 51.4 230.1 49.7C231.5 48 232.2 45.5 232.2 42.1C232.2 38.8 231.5 36.3 230 34.6C228.6 32.9 226.6 32.1 224 32.1C221.3 32.1 219.3 33 217.8 34.8C216.2 36.5 215.5 39 215.5 42.3ZM250.5 34.8C250.5 35.8 250.8 36.7 251.5 37.3C252.2 37.9 253.6 38.6 255.9 39.5C258.8 40.7 260.9 42 262 43.4C263.2 44.9 263.8 46.6 263.8 48.7C263.8 51.6 262.7 54 260.4 55.7C258.2 57.5 255.1 58.4 251.3 58.4C250 58.4 248.6 58.2 247 57.9C245.4 57.6 244.1 57.2 243 56.7V49.5C244.3 50.4 245.8 51.2 247.3 51.7C248.8 52.2 250.2 52.5 251.5 52.5C253.1 52.5 254.4 52.3 255.1 51.8C255.9 51.3 256.3 50.6 256.3 49.5C256.3 48.5 255.9 47.6 255.1 47C254.3 46.3 252.7 45.5 250.5 44.6C247.8 43.5 245.9 42.2 244.8 40.8C243.7 39.4 243.1 37.6 243.1 35.4C243.1 32.6 244.2 30.3 246.4 28.5C248.6 26.7 251.5 25.8 255 25.8C256.1 25.8 257.3 25.9 258.6 26.2C259.9 26.4 261.1 26.8 262 27.1V34C261 33.4 259.9 32.8 258.6 32.3C257.3 31.8 256 31.6 254.8 31.6C253.4 31.6 252.3 31.9 251.6 32.4C250.9 33.1 250.5 33.8 250.5 34.8ZM266.9 42.6C266.9 37.5 268.3 33.4 271.2 30.4C274.1 27.4 278.1 25.9 283.3 25.9C288.1 25.9 291.9 27.3 294.6 30.2C297.3 33.1 298.7 37 298.7 41.9C298.7 46.9 297.3 50.9 294.4 53.9C291.5 56.9 287.6 58.4 282.6 58.4C277.8 58.4 274 57 271.2 54.2C268.4 51.3 266.9 47.4 266.9 42.6ZM274.5 42.3C274.5 45.5 275.2 48 276.7 49.7C278.2 51.4 280.3 52.3 283 52.3C285.7 52.3 287.7 51.4 289.1 49.7C290.5 48 291.2 45.5 291.2 42.1C291.2 38.8 290.5 36.3 289 34.6C287.6 32.9 285.6 32.1 283 32.1C280.3 32.1 278.3 33 276.8 34.8C275.3 36.5 274.5 39 274.5 42.3ZM322.9 32.6H312V57.6H304.6V32.6H299.4V26.6H304.6V22.3C304.6 19 305.7 16.4 307.8 14.3C309.9 12.2 312.6 11.2 315.9 11.2C316.8 11.2 317.6 11.2 318.3 11.3C319 11.4 319.6 11.5 320.1 11.7V18C319.9 17.9 319.4 17.7 318.8 17.5C318.2 17.3 317.5 17.2 316.7 17.2C315.2 17.2 314 17.7 313.2 18.6C312.4 19.6 312 21 312 22.8V26.5H322.9V19.5L330.2 17.3V26.5H337.6V32.5H330.2V47C330.2 48.9 330.5 50.3 331.2 51C331.9 51.8 333 52.2 334.5 52.2C334.9 52.2 335.4 52.1 336 51.9C336.6 51.7 337.1 51.5 337.6 51.2V57.2C337.1 57.5 336.4 57.7 335.3 57.9C334.2 58.1 333.2 58.2 332.1 58.2C329 58.2 326.7 57.4 325.2 55.7C323.7 54.1 322.9 51.6 322.9 48.3V32.6V32.6Z" fill="#737373"></path><path d="M34.2 0H0V34.2H34.2V0Z" fill="#F25022"></path>
                    <path d="M72 0H37.8V34.2H72V0Z" fill="#7FBA00"></path>
                    <path d="M34.2 37.8H0V72H34.2V37.8Z" fill="#00A4EF"></path>
                    <path d="M72 37.8H37.8V72H72V37.8Z" fill="#FFB900"></path>
                </g>
                <defs>
                    <clipPath id="clip0">
                        <rect width="337.6" height="72" fill="white"></rect>
                    </clipPath>
                </defs>
            </svg>
        </svg>
        """;

    [Parameter]
    public SplashScreenContent Content { get; set; } = default!;

    [CascadingParameter]
    public FluentDialog Dialog { get; set; } = default!;

    protected override void OnInitialized()
    {
        Content.RefreshProperties = () => StateHasChanged();
    }

    protected override async Task OnAfterRenderAsync(bool firstRender)
    {
        if (firstRender && Content.DisplayTime > 0)
        {
            // Simulation of loading process
            await Task.Delay(Content.DisplayTime);

            // Close the dialog
            await Dialog.CloseAsync();
        }
    }
}
